package com.car.servlet;

import com.car.service.UserService;
import com.car.entyti.Carpool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/carpool")
public class carpool_info extends HttpServlet {
    UserService userService = new UserService();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//      提取encode
//        String encode = getServletContext().getInitParameter("encode");
//    参数encode
//        req.setCharacterEncoding(encode);


        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=utf-8");

        String be = req.getParameter("be_city");
        String de = req.getParameter("de_city");
        String time = req.getParameter("de_time");
        String n_people = req.getParameter("num_people");
        String c_people = req.getParameter("chek_people");
        String remarks = req.getParameter("remarks");
        String car_type = req.getParameter("car_type");
        String cost = req.getParameter("cost");
        String usertype = req.getParameter("usertype");
//        String sj = req.getParameter("s");
//        String c = req.getParameter("c");

        Carpool carpool = new Carpool();
        carpool.setBecity(be);
        carpool.setDecity(de);
        carpool.setDeptime(time);
        carpool.setNum_people(n_people);
        carpool.setChek_people(c_people);
        carpool.setRemarks(remarks);
        carpool.setMotor_type(car_type);
        carpool.setCost(cost);
        carpool.setUsertype(usertype);



        if (userService.publish(carpool) != null) {
            req.getSession().setAttribute("msg", "发布成功");
            resp.sendRedirect(req.getContextPath());

        } else {
            req.getSession().setAttribute("msg", "发布失败");
            resp.sendRedirect(req.getContextPath());
        }

    }
}
